package com.xbongbong.saas.script.tempenum.product;

import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.LinkedAttrPoJo;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.SummaryTypeEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.paas.field.LinkInfoPojo;
import com.xbongbong.paas.field.LinkKeyFieldInfoPojo;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.product.OutstockProductEnum;
import com.xbongbong.saas.enums.product.ProductionOrderMaterielProductEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/10/12 10:32
 * @since v1.0
 */
@Getter
public enum TempProductionOrderMaterieProductEnum {
    PRODUCT(ProductionOrderMaterielProductEnum.PRODUCT),
    WAREHOUSE(ProductionOrderMaterielProductEnum.WAREHOUSE),
    UNIT(ProductionOrderMaterielProductEnum.UNIT),
    NUM(ProductionOrderMaterielProductEnum.NUM),
    STOCK(ProductionOrderMaterielProductEnum.STOCK),
    MEMO(ProductionOrderMaterielProductEnum.MEMO),
    LOSS_RATE(ProductionOrderMaterielProductEnum.LOSS_RATE),
    OUTSTOCK_NUM(ProductionOrderMaterielProductEnum.OUTSTOCK_NUM),
    WAIT_OUTSTOCK_NUM(ProductionOrderMaterielProductEnum.WAIT_OUTSTOCK_NUM),
    ;

    private ProductionOrderMaterielProductEnum productionOrderMaterielProductEnum;

    TempProductionOrderMaterieProductEnum(ProductionOrderMaterielProductEnum productionOrderMaterielProductEnum) {
        this.productionOrderMaterielProductEnum = productionOrderMaterielProductEnum;
    }

    public static void initProduct(FieldAttrEntity fieldAttrEntity, List<LinkedAttrPoJo> linkedAttrPoJoList,List<LinkedAttrPoJo> linkedShowPoJoList, PaasFormEntityExt paasFormEntity){
        LinkInfoPojo linkInfoPojo = new LinkInfoPojo();
        linkInfoPojo.setLinkBusinessType(XbbRefTypeEnum.PRODUCT.getCode());
        linkInfoPojo.setLinkedAttr(linkedAttrPoJoList);
        linkInfoPojo.setLinkSaasMark(SaasMarkEnum.SAAS.getCode());
        linkInfoPojo.setLinkKey(linkedAttrPoJoList.get(1).getAttr());
        linkInfoPojo.setLinkFormId(paasFormEntity.getId());
        linkInfoPojo.setLinkMenuId(paasFormEntity.getMenuId());
        linkInfoPojo.setLinkAppId(paasFormEntity.getAppId());
        linkInfoPojo.setCondition(new ArrayList<>());
        LinkKeyFieldInfoPojo linkKeyFieldInfoPojo = new LinkKeyFieldInfoPojo();
        BeanUtil.copyProperties(linkedAttrPoJoList.get(1),linkKeyFieldInfoPojo);
        linkInfoPojo.setLinkKeyAttr(linkKeyFieldInfoPojo);
        linkInfoPojo.setLinkedShowAttr(linkedShowPoJoList);
        fieldAttrEntity.setLinkInfo(linkInfoPojo);
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(1);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_VISIBLE_PERMISSION.getAlias()));
    }

    // 初始化产品中的其他属性
    public static void initWarehouse(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.PRODUCT_WAREHOUSE.getCode());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(true);
        saasParticularAttributePoJo.setRelyAttr(OutstockProductEnum.PRODUCT.getAttr());
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.PRODUCT.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setShowEditable(1);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_VISIBLE_CORRELATION_FIELD.getAlias()));
    }

    public static void initNum(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setIsForbidden(1);
        fieldAttrEntity.setShowEditable(1);
        fieldAttrEntity.setNumAccuracyAndScopeHide(1);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_MONEY_TYPE.getAlias()));
    }

    public static void initLossRate(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_MONEY_TYPE.getAlias()));
    }

    public static void initUnit(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setEditable(0);
        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_ITEMS.getAlias(),
                ForbiddenSettingEnum.DISABLE_RULE.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
    }

    public static void initMemo(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setIsForbidden(1);
        fieldAttrEntity.setShowEditable(1);
    }

    public static void initStock(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setNumAccuracyAndScopeHide(1);
        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_MONEY_TYPE.getAlias(),ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
    }

    public static void initOutNum(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.NONE.getType());
        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_ITEMS.getAlias(),ForbiddenSettingEnum.DISABLE_MEMO.getAlias(), ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias(),ForbiddenSettingEnum.DISABLE_TYPE.getAlias(),ForbiddenSettingEnum.DISABLE_MONEY_TYPE.getAlias(),ForbiddenSettingEnum.DISABLE_RULE.getAlias(),ForbiddenSettingEnum.DISABLE_SUMMARY.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
    }
    public static void initWaitOutNum(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.NONE.getType());
        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_ITEMS.getAlias(),ForbiddenSettingEnum.DISABLE_MEMO.getAlias(), ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias(),ForbiddenSettingEnum.DISABLE_TYPE.getAlias(),ForbiddenSettingEnum.DISABLE_MONEY_TYPE.getAlias(),ForbiddenSettingEnum.DISABLE_RULE.getAlias(),ForbiddenSettingEnum.DISABLE_SUMMARY.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
    }
}
